package controller;

import Dao.QuestionDao;
import entity.Question;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class QuestionUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String questionId, title, optionA, optionB, optionC, optionD, answer;
        questionId = request.getParameter("questionId");
        QuestionDao dao = new QuestionDao();
        title = request.getParameter("title");
        optionA = request.getParameter("optionA");
        optionB = request.getParameter("optionB");
        optionC = request.getParameter("optionC");
        optionD = request.getParameter("optionD");
        answer = request.getParameter("answer");
        Question question = new Question(Integer.parseInt(questionId), title, optionA, optionB, optionC, optionD, answer);
        int result = dao.update(question, request);
        request.setAttribute("result", result);
        request.getRequestDispatcher("/question_update_result.jsp").forward(request, response);
    }
}
